﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using KingsSharp.Core;

namespace KingsSharp.Core.Data.Entity
{
    /// <summary>
    /// 动态注册mapper映射
    /// </summary>
    public class MapperRegisters
    {
      /// <summary>
        /// 注册所有的mapper实现
      /// </summary>
      /// <param name="ass">指定的程序集</param>
        public static void RegisterAll(params Assembly[] ass)
        {
            Type baseType = typeof(IMapper);
            var mapperTypes = ass.SelectMany(a => a.GetTypes().Where
               (type => baseType.IsAssignableFrom(type) && !type.IsAbstract)).ToArray();
            foreach (var type in mapperTypes)
            {
                IMapper mapper = (IMapper)Activator.CreateInstance(type);
                mapper.Register();
            }
        }
    }
}
